<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
        <!-- 得计数排序对于数据范围很大的数组，
        需要大量时间和内存。
        例如：计数排序是用来排序0到100之间的数字的最好的算法 -->
    <script>
    Array.prototype.countSort = function(){
        const c = []
        console.log("one:" + c)
        for(let i = 0; i < this.length; i++){
            const j = this[i]
            c[j] >= 1 ? c[j] ++ : (c[j] = 1)
        }
        console.log("two:" + c.length)
        const d = []
        console.log(d)
        for(let j = 0; j < c.length; j++){
            if(c[j]){
                while(c[j] > 0){
                    d.push(j)
                    c[j]--
                }
            }
        }
        return d
    }

    const arr = [11, 9, 6, 8, 1, 3, 5, 1, 1, 0, 100]
    console.log(arr.countSort())
    </script>
</body>
</html>